/**
 * @模块名：gm
 * @包名：ltd.snowland.utils
 * @描述：CreateCer.java
 * @版本：1.0
 * @创建人：李凯
 * @创建时间：2020年12月8日下午7:08:38
 */
package ltd.snowland.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;

import org.bouncycastle.util.encoders.Base64;

/**
 * @模块名：gm
 * @包名：ltd.snowland.utils
 * @类名称：CreateCer
 * @类描述：
 * @版本：1.0
 * @创建人：李凯
 * @创建时间：2020年12月8日下午7:08:38
 */
public class CreateCer {

	public static void main(String[] args) {
		createCer();
	}

	public static void createCer() {
		String pvkStr = "MIIELwYJKoZIhvcNAQcEoIIEIDCCBBwCAQExgfcwgfQCAQAwLTAmMQswCQYDVQQGEwJDTjEXMBUGA1UEAwwOQ01DQSBTZXJ2ZXIgQ0ECAwcuUDAJBgcqhkjOPQIBBIG0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACY5i37Iesn2fACB6DRY4jdOHs34zdfUbGpqvJUo6O8IAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAo5P2+UA963I8godXESAfaEPxFYkmfwcbe37IVaU6hsWTEuYua8LDHa36KkmhtJ137ApIP8PdvPEDBdO8AW02PBAAAAC/6SGO7axwzwXKpRxanI7HMQwwCgYIKoZIhvcNAgYwgZcGCSqGSIb3DQEHBjAHBgUrDgMCCICBgN+TYRuIkbz46K5c7m2SvKPJT5XylUBxNKrZsUIIluBjxrMKWewxN5hfxVWQjbokTicQRDkY0k4fTnjmgBAOECedj0xj+6sATYxSTRx4qwfnuoEFTrrgZnOx5obL4McHEm55OtTyfPplFkkHTD3Pi5vP+Dk2Uqempe3GVVA04Cn+oIIBmjCCAZYwggE7oAMCAQICAwcuUDAMBggqgRzPVQGDdQUAMCYxCzAJBgNVBAYTAkNOMRcwFQYDVQQDDA5DTUNBIFNlcnZlciBDQTAeFw0xOTA2MTIxMDExMjBaFw0yOTA2MTIxMDExMjBaMCIxCzAJBgNVBAYTAkNOMRMwEQYDVQQDDApLTUMgU0VSVkVSMFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAESKHK3dFamO8KBJvLKJZHJmSb04jFQtvbsG1MVmSKtgGq0OtXaZyP1Q+Vr6K5Dvd5JpGGNZN0HjnnQ7wTjlleZaNaMFgwHwYDVR0jBBgwFoAUTnChXbHDOU0vgcwKcREJwQ6ObkcwCQYDVR0TBAIwADALBgNVHQ8EBAMCAYIwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMBMAwGCCqBHM9VAYN1BQADRwAwRAIgPVTblomLQnXTFQDxtLO7KEvRURNEFDfb8fQ8UdtTq9MCINYqE/a7YIjMZSpD1Qw0ETVmGqsZZN5a2m9XjRMwLm1TMYHWMIHTAgEAMC0wJjELMAkGA1UEBhMCQ04xFzAVBgNVBAMMDkNNQ0EgU2VydmVyIENBAgMHLlAwCgYIKoZIhvcNAgagPzAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcGMCMGCSqGSIb3DQEJBDEWBBTc5DW5wBae9jsq9/aSX3UUCCsxOjAKBggqgRzPVQGCLQRGMEQCIGbRbe3yXZ+fcaDzBakwwf3DDtGPx/0t2TsS7SS+tRGjAiCM8hgnqC4dbGiSLNa2jN+luWWftx2yN1x0KRijgP7hHQ==";
		byte[] pvkBit = Base64.decode(pvkStr);
		File pvkTempFile = new File("G:\\test2.csr");
		FileOutputStream fos = null;
		FileInputStream in = null;
		try {
			pvkTempFile.createNewFile();
			fos = new FileOutputStream(pvkTempFile);
			fos.write(pvkBit);
			fos.flush();
			CertificateFactory cf = CertificateFactory.getInstance("X.509");
			in = new FileInputStream("G:\\test2.csr");
			Certificate c = cf.generateCertificate(in);
			PublicKey pk = c.getPublicKey();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				fos.close();
				in.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
